﻿using LyData.Data;
using System;
using System.Data;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_FriendLinkList : System.Web.UI.Page
{
    protected void Bind()
    {
        IDb db = new DbFactory().DriverDb();
        db.Open();
        string whereStr = string.Format("SiteLanguage={0} ", SiteInfo.SiteLanguage());
        DataTable table = db.DataTable("FriendLinkId,Title,Type,Url,LogoPath", "FriendLink", whereStr, "FriendLinkId DESC");
        db.Close();
        this.FriendLinkList.DataSource = table;
        this.FriendLinkList.DataBind();
    }

    protected void FriendLinkList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.FriendLinkList.PageIndex = e.NewPageIndex;
        this.Bind();
    }

    protected void FriendLinkList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
    }

    protected void FriendLinkList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        HyperLink link = (HyperLink)e.Row.FindControl("EditHyperLink");
        Button button = (Button)e.Row.FindControl("DelBt");
        if (button != null)
        {
            if (!ManagerLogin.ValidateRole("C_FriendLinkEdit.aspx"))
            {
                link.Enabled = false;
            }
            if (!ManagerLogin.ValidateRole("C_FriendLinkList.aspx"))
            {
                button.Enabled = false;
            }
        }
    }

    protected void FriendLinkList_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int rowIndex = e.RowIndex;
        string str = this.FriendLinkList.DataKeys[rowIndex].Values[0].ToString();
        IDb db = new DbFactory().DriverDb();
        db.Open();
        db.Delete("friendLink", string.Format("FriendLinkId={0}", str));
        db.Close();
        this.Bind();
        this.Msg.Text = "友情链接删除成功！";
        this.Msg.Visible = true;
    }

    protected void FriendLinkList_RowEditing(object sender, GridViewEditEventArgs e)
    {
    }

    protected void FriendLinkList_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Msg.Visible = false;
        if (!base.IsPostBack)
        {
            this.Bind();
        }
    }
}
